package com.zzyl.controller;

import com.zzyl.base.BaseEntity;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 护理项目
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页条件查询
     *
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(@ApiParam(value = "护理项目名称") String name,
                                                                    @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
                                                                    @ApiParam(value = "当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                    @ApiParam(value = "每页显示的数量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> pageVo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(pageVo);
    }

    /**
     * 新增护理项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult caretProject(@ApiParam(value = "nursingProjectDto传输对象", required = true)
                                       @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.caretProject(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 根据id查询护理
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理")
    public ResponseResult<NursingProjectVo> getById(@ApiParam(value = "路径参数")
                                                    @PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    /**
     * 编辑护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult updateProject(@ApiParam(value = "护理对象")
                                        @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.updateProject(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteProject(@ApiParam(value = "路径参数")
                                        @PathVariable("id") Long id){
        nursingProjectService.deleteProject(id);
        return ResponseResult.success();
    }

    /**
     * 查询所有的护理项目
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<NursingProjectVo> getByAllId(){
        return ResponseResult.success(nursingProjectService.getByAllId());
    }

    /**
     * 状态禁用启用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用状态")
    public ResponseResult updateStatus( @ApiParam("路径参数id")
                                        @PathVariable("id") Long id,
                                        @ApiParam("路径参数status")
                                        @PathVariable("status") Integer status){
        nursingProjectService.updateStatus(id,status);
        return ResponseResult.success();
    }
}